package main

import (
	"fmt"
	"reflect"
	"strings"
	"time"
)

type Test struct {
	name string
	age  int32
}

func NewTest(name string, age int32) *Test {
	return &Test{name: name, age: age}
}

type M = map[string]interface{}
type MM map[string]interface{}

// 进度条效果
func bar() {
	var count = 30
	bar := "\r[%-30s]"

	for i := 0; i < count; i++ {
		fmt.Printf(bar, strings.Repeat("=", i)+">")
		time.Sleep(100 * time.Millisecond)
	}
	fmt.Printf(bar+" Done!", strings.Repeat("=", count))
}

func printTest() {
	test := Test{
		name: "sljdflj",
		age:  21,
	}

	fmt.Printf("%%v：%v\n", test)
	fmt.Printf("%%+v:%+v\n", test)
	fmt.Printf("%%+v:%+v\n", &test)
	fmt.Printf("%%#v:%#v\n", test)
	fmt.Printf("%%v:%v\n", test.name)
	fmt.Printf("%%+v:%+v\n", test.name)
	fmt.Printf("%%#v:%#v\n", test.name)

	var ss rune
	ss = 's'
	fmt.Println(ss)

	fmt.Printf("%f\n", 1.23)
	fmt.Printf("%9f\n", 1.23)
	fmt.Printf("%9.2f\n", 1.23) //输出长度为9，保留2位小数
	fmt.Printf("%1.2f\n", 1.23) //输出长度为1，保留2位小数，当1和2冲突的时候，2有效，1无效
	fmt.Printf("%9.f\n", 1.23)  //输出长度为9,没有小数位
	fmt.Printf("%.2f\n", 1.234) //保留两位小数
	fmt.Printf("%.2f\n", 1.235) //会四舍五入

	fmt.Println(M{"ss": "sdf"})
	fmt.Println(MM{"ss": "sdf"})
	fmt.Println(reflect.TypeOf(M{"ss": "sdf"}))
	fmt.Println(reflect.TypeOf(MM{"ss": "sdf"}))

	fmt.Printf("%T\n", test)

	v := Test{
		name: "sljdflj",
		age:  21,
	}

	p1 := &v
	p2 := &p1
	p3 := &p2
	fmt.Println(p1)
	fmt.Println(p2)
	fmt.Println(p3)
	fmt.Printf("%v\n", p3)
	fmt.Printf("%p\n", p3)

	updateTest(p1)
	fmt.Println(p1)

	var xx Test
	xx.name = "yyy"
	fmt.Println(xx)
}

func updateTest(p *Test) {
	p.name = "xxxxx"
}

func main() {
	printTest()
	bar()
}
